package com.sysu.minsysu.utils;

import com.sysu.minsysu.R;

import android.app.Activity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;

public class IconTrangeAnimation {

	public static AnimationSet[] getIconTrangeAnimation( Activity activity, final View[] startViews, final View[] endViews, View[] animViews){
		
		final int count = startViews.length;
		int screenWidth = activity.getWindowManager().getDefaultDisplay().getWidth();
		int temp = screenWidth/count;
		int[] start_left = new int[count];
		int[] start_top = new int[count];
		int[] end_left = new int[count];
		int[] end_top = new int[count]; 
		for( int i=0; i<count; i++ ){
			start_left[i] = startViews[i].getLeft();
			start_top[i] = startViews[i].getTop(); 
			end_left[i] = temp*i;
			end_top[i] = 0;
		}
		
		AnimationSet[] set = new AnimationSet[count];
		
		for( int i=0; i<count; i++ ){
			AnimationSet animation = new AnimationSet(true);
			animation.setDuration(2000);
			//Animation animation = AnimationUtils.loadAnimation(activity, R.anim.icon_trans);
			animation.setInterpolator( AnimationUtils.loadInterpolator(activity, android.R.anim.decelerate_interpolator));			
			
			TranslateAnimation transAnimation = new TranslateAnimation(start_left[i], start_top[i], end_left[i], end_top[i]);
			transAnimation.setDuration(2000);
			animation.addAnimation(transAnimation);
			
			ScaleAnimation scaleAnimation = new ScaleAnimation(2, 0.3f, 2, 0.3f);
			scaleAnimation.setDuration(2000);
			animation.addAnimation(scaleAnimation);
			
			
			set[i] = animation;
		}
		
		return set;
	}
	
}
